﻿using CoreShop.Model;
using SqlSugar.Extensions;
using Sunny.UI;
using System;
using System.Drawing;

namespace CoreShop.App
{
    public partial class UIFoodSpecItem : UIUserControl
    {
        public int number = 0;
        public corecmsfoodspecPost foodspec { get; set; }
        public UIFoodSpecItem(int _number, corecmsfoodspecPost _foodspec)
        {
            foodspec = _foodspec;
            InitializeComponent();
            if (_number == 1) btnDelete.Visible = false;
            this.swhIsDefault.Active = foodspec.isDefault;
            this.lblSpecName.Text = foodspec.specName.ObjToString();
            this.txtPosPrice.Text = foodspec.posPrice.ObjToString();
            this.txtVipPrice.Text = foodspec.vipPrice.ObjToString();
            this.txtPurPrice.Text = foodspec.purPrice.ObjToString();
            this.txtCode.Text = foodspec.code.ObjToString();
            this.lblSpecName.Focus();
        }

        public corecmsfoodspecPost GetModelValue()
        {
            this.foodspec.isDefault = this.swhIsDefault.Active;
            this.foodspec.specName = this.lblSpecName.Text;
            this.foodspec.posPrice = this.txtPosPrice.Text.ObjToDecimal(0);
            this.foodspec.vipPrice = this.txtVipPrice.Text.ObjToDecimal(0);
            this.foodspec.purPrice = this.txtPurPrice.Text.ObjToDecimal(0);
            this.foodspec.code = this.txtCode.Text;
            return this.foodspec;
        }

        public event EventHandler DeleteSpec;
        private void btnDelete_Click(object sender, System.EventArgs e)
        {
            DeleteSpec?.Invoke(this, e);
        }
    }
}
